| Conditions | 4 |
| Paths | 10 |
| Total Lines | 136 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | (function ($) { |
||
| 122 | var stateBarMenu = function () { |
||
| 123 | |||
| 124 | var ACTIVE_THRESHOLD = 55; |
||
| 125 | |||
| 126 | $.fn.isVisible = function (type) { |
||
| 127 | // Current distance from the top of the page |
||
| 128 | var windowScrollTopView = $(window).scrollTop(); |
||
| 129 | // Current distance from the top of the page, plus the height of the window |
||
| 130 | var windowBottomView = windowScrollTopView + $(window).height(); |
||
| 131 | // Element distance from top |
||
| 132 | var elemTop = $(this).offset().top; |
||
| 133 | // Element distance from top, plus the height of the element |
||
| 134 | if (type == "top") { |
||
| 135 | offset = 50; |
||
| 136 | } else { |
||
| 137 | offset = +380; |
||
| 138 | } |
||
| 139 | var elemBottom = elemTop + $(this).height() + offset; |
||
| 140 | //console.log("wTop " + windowScrollTopView + " wB " + windowBottomView + " eTop" + elemTop); |
||
| 141 | return ((elemBottom <= windowBottomView) && (elemTop >= windowScrollTopView)); |
||
| 142 | }; |
||
| 143 | |||
| 144 | |||
| 145 | if ($('.state-bar').length == 0) return; |
||
| 146 | var fixBarTop = $('.state-bar').offset().top; |
||
| 147 | var donationSection = $("#donation-amount").offset().top; |
||
| 148 | var donationPaymentSection = $("#donation-payment").offset().top; |
||
| 149 | var donationTypeSection = $("#donation-type").offset().top; |
||
| 150 | |||
| 151 | |||
| 152 | if ($(window).width() < 1023) { |
||
| 153 | $(window).scroll(function () { |
||
| 154 | var currentScroll = $(window).scrollTop(); |
||
| 155 | if (currentScroll + 70 >= fixBarTop) { |
||
| 156 | $('.state-bar').addClass('active'); |
||
| 157 | $('.menu-main').addClass('under-bar'); |
||
| 158 | if ($('.footer').isVisible('top')) { |
||
| 159 | $(".state-bar").removeClass('active'); |
||
| 160 | $('.menu-main').removeClass('under-bar'); |
||
| 161 | } else { |
||
| 162 | $(".state-bar").addClass('active'); |
||
| 163 | $('.menu-main').addClass('under-bar'); |
||
| 164 | } |
||
| 165 | } else { |
||
| 166 | $('.state-bar').removeClass('active'); |
||
| 167 | $('.menu-main').removeClass('under-bar'); |
||
| 168 | } |
||
| 169 | if (currentScroll >= donationSection - ACTIVE_THRESHOLD) { |
||
| 170 | $('.state-overview .amount').addClass('enabled'); |
||
| 171 | } else { |
||
| 172 | $('.state-overview .amount').removeClass('enabled'); |
||
| 173 | } |
||
| 174 | }); |
||
| 175 | } else { |
||
| 176 | $(window).scroll(function () { |
||
| 177 | var currentScroll = $(window).scrollTop(); |
||
| 178 | if ($('body#donation').length) { |
||
| 179 | var initialTop = 200; |
||
| 180 | } else if ($('body#membership').length) { |
||
| 181 | var initialTop = 650; |
||
| 182 | } |
||
| 183 | |||
| 184 | |||
| 185 | if (currentScroll >= initialTop) { |
||
| 186 | $('.state-overview .wrap-bar').addClass('fixed'); |
||
| 187 | //console.log("wrap bar" + currentScroll); |
||
| 188 | } else { |
||
| 189 | $('.state-overview .wrap-bar').removeClass('fixed'); |
||
| 190 | } |
||
| 191 | |||
| 192 | |||
| 193 | if (($('.state-bar-lateral .wrap-bar').outerHeight() + $('.state-bar-lateral .wrap-bar').offset().top ) > ( $('.form-shadow-wrap').offset().top + $('.form-shadow-wrap').outerHeight() + 150)) { |
||
| 194 | $('.state-bar-lateral').removeClass('active'); |
||
| 195 | } else { |
||
| 196 | $('.state-bar-lateral').addClass('active'); |
||
| 197 | } |
||
| 198 | |||
| 199 | /*if ($(".overview").isVisible('lateral') || $('#other-info').isVisible('lateral')) { |
||
| 200 | $(".state-bar-lateral").removeClass('active'); |
||
| 201 | } else { |
||
| 202 | $(".state-bar-lateral").addClass('active'); |
||
| 203 | }*/ |
||
| 204 | }); |
||
| 205 | } |
||
| 206 | |||
| 207 | |||
| 208 | if ($("body#membership").length) { |
||
| 209 | var memberTypeSection = $("#membership-type").offset().top; |
||
| 210 | $(window).scroll(function () { |
||
| 211 | var currentScroll = $(window).scrollTop(); |
||
| 212 | var typeMemberElements = $('.state-overview .member-type'); |
||
| 213 | var donatorElements = $('.state-overview .donator-type'); |
||
| 214 | var amountElements = $('.state-overview .amount'); |
||
| 215 | var paymentElemnts = $('.state-overview .payment-method'); |
||
| 216 | |||
| 217 | typeMemberElements.removeClass('enabled'); |
||
| 218 | donatorElements.removeClass('enabled'); |
||
| 219 | amountElements.removeClass('enabled'); |
||
| 220 | paymentElemnts.removeClass('enabled'); |
||
| 221 | ACTIVE_THRESHOLD = 60; |
||
| 222 | if (currentScroll >= donationPaymentSection - ACTIVE_THRESHOLD) { |
||
| 223 | paymentElemnts.addClass('enabled'); |
||
| 224 | } |
||
| 225 | else if (currentScroll >= donationSection - ACTIVE_THRESHOLD) { |
||
| 226 | amountElements.addClass('enabled'); |
||
| 227 | } |
||
| 228 | else if (currentScroll >= donationTypeSection - ACTIVE_THRESHOLD) { |
||
| 229 | donatorElements.addClass('enabled'); |
||
| 230 | } |
||
| 231 | else if (currentScroll >= memberTypeSection - ACTIVE_THRESHOLD) { |
||
| 232 | typeMemberElements.addClass('enabled'); |
||
| 233 | } |
||
| 234 | }); |
||
| 235 | } else { |
||
| 236 | $(window).scroll(function () { |
||
| 237 | var currentScroll = $(window).scrollTop(); |
||
| 238 | var amountElements = $('.state-overview .amount'); |
||
| 239 | var paymentElemnts = $('.state-overview .payment-method'); |
||
| 240 | var donatorElements = $('.state-overview .donator-type'); |
||
| 241 | |||
| 242 | amountElements.removeClass('enabled'); |
||
| 243 | paymentElemnts.removeClass('enabled'); |
||
| 244 | donatorElements.removeClass('enabled'); |
||
| 245 | if (currentScroll >= donationTypeSection - ACTIVE_THRESHOLD) { |
||
| 246 | donatorElements.addClass('enabled'); |
||
| 247 | } |
||
| 248 | else if (currentScroll >= donationPaymentSection - ACTIVE_THRESHOLD) { |
||
| 249 | paymentElemnts.addClass('enabled'); |
||
| 250 | } |
||
| 251 | else if (currentScroll >= donationSection - ACTIVE_THRESHOLD) { |
||
| 252 | amountElements.addClass('enabled'); |
||
| 253 | } |
||
| 254 | }); |
||
| 255 | } |
||
| 256 | |||
| 257 | }; |
||
| 258 | |||
| 373 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.